
import GameWorld from "./battle/GameWorld";
import Unit from "./battle/Unit";
import { UnitStateEnum } from "./battle/UnitStateMachine";
import { GameEvent } from "./config/EventConfig";
import GroupConfig from "./config/GroupConfig";
import EventManager from "./manager/EventManager";
import { UIManager } from "./ui/UIManager";
const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    map: cc.Node = null;

    units: Unit[] = [];
    units1: Unit[] = [];
    isstart = false;
    world: GameWorld
    async start() {
        EventManager.instance.on(GameEvent.GAMEOVER, (groupId) => {
            UIManager.instance.showToast('Group' + groupId + '获胜');
        });
        this.world = GameWorld.create(GroupConfig[3], GroupConfig[4], this.map);
        console.log(this.world);

        this.world.allUnits.forEach((unit) => {
            unit.changeState(UnitStateEnum.FindAim);
        });
        this.isstart = true;

    }

    update(dt) {
        if (!this.isstart) {
            return;
        }
        this.world.update(dt);
    }
}
